package shop.controller;


import jakarta.servlet.http.HttpSession;
import jakarta.validation.Valid;
import org.flown.shop.SessionAttribute;
import org.flown.shop.entity.User;
import org.flown.shop.entity.error.SaveError;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import shop.entity.GoodsComment;
import shop.service.GoodsCommentService;

import java.io.IOException;


@RequestMapping("/user")
@Controller
public class GoodsCommentUserController
{
    @Autowired
    private GoodsCommentService service_goods_comment;


    /**
     * goodsID
     * storeID
     * ordersID
     * detailStar
     * logisticsStar
     * attitudeStar
     * content "["评价", {"name":"name", "format":"png"}, {}]"
     * base64Picture[]
     * */
    @ResponseBody
    @PostMapping("/publishGoodsComment")
    public String publishGoodsComment(HttpSession session, @Valid GoodsComment comment)
            throws SaveError
    {
        User user = (User)session.getAttribute(SessionAttribute.USER.getName());
        if (user == null)
            return "未登录";

        comment.setUserID(user.getID());
        if (this.service_goods_comment.insertGoodsComment(comment) == 0)
            return "评论发表失败";
        return "评论发表成功";
    }


}

